# Soccer Makefile
# 
# Make shared, static or debug targets.
# 
# Distribution: GPL 

OS := $(shell uname)
OBJ = build
OBJ2 = dsa
TARGET = game
RENAME = install_name_tool
GNATMAKE = gnatmake -D $(OBJ)
PO_GNATDIST = po_gnatdist
CARGS = -cargs -O3 -gnatp -gnatwu
BARGS = -bargs
LARGS = -largs
VERBOSE = -v
SHARED = libgnat-4.3.dylib
ADA_LIB ?= /usr/local/ada-4.3/lib
.PHONEY: clean cleaner dist-clean tar

all:
	@echo ""
	@echo "Soccer build targets:"
	@echo ""
	@echo "    shared     Use the shared Ada libraries."
	@echo "    static     Link the Ada libraries statically."
	@echo "    distrib    Link the Ada libraries for distributed system."	
	@echo "    debug      Enable debugging."
	@echo ""
	@echo "Support targets:"
	@echo ""
	@echo "    clean      Remove *.ali *.o b~.*"
	@echo "    cleaner    Remove target, too."
	@echo "    dist-clean Remove Xcode build directory, too."
	@echo "    tar        Build a clean distribution tarball."
	@echo ""

shared: $(OBJ)
shared: INCLUDE = $(shell gtkada-config --cflags)
shared: BARGS += -shared
shared: LARGS += $(shell gtkada-config --libs)
shared: LARGS += -dead_strip
shared: *.ad[sb]
	@echo "building with shared libraries:"
	$(GNATMAKE) $(TARGET) $(INCLUDE) $(CARGS) $(BARGS) $(LARGS)
ifeq ($(OS), Darwin)
#	$(RENAME) -change $(SHARED) $(ADA_LIB)/$(SHARED) $(TARGET)
endif

static: $(OBJ)
static: INCLUDE = $(shell gtkada-config --static --cflags)
static: BARGS += -static
static: LARGS += $(shell gtkada-config --static --libs)
static: LARGS += -dead_strip
static: *.ad[sb]
	$(GNATMAKE) $(TARGET) $(INCLUDE) $(CARGS) $(BARGS) $(LARGS)

distrib: $(OBJ)
distrib: INCLUDE = $(shell gtkada-config --cflags)
distrib: BARGS += -shared
distrib: LARGS += $(shell gtkada-config --libs)
distrib: LARGS += -dead_strip
distrib: *.ad[sb]
distrib:
	@echo "building with shared libraries:"
	$(PO_GNATDIST) Dist_Soccer.cfg $(INCLUDE) $(CARGS) $(BARGS) $(LARGS)

debug: $(OBJ)
debug: INCLUDE = $(shell gtkada-config --static --cflags)
debug: BARGS += -static
debug: LARGS += $(shell gtkada-config --static --libs)
debug: *.ad[sb]
	$(GNATMAKE) -g $(TARGET) $(INCLUDE) $(CARGS) $(BARGS) $(LARGS)

$(OBJ):
	mkdir $(OBJ)

clean:
	${RM} $(OBJ)/* b~* 

cleaner: clean
	${RM} $(TARGET)

dist-clean: cleaner
	${RM} -rf $(OBJ)
	${RM} -rf $(OBJ2)

tar: dist-clean
ifeq ($(OS), Darwin)
	(export COPYFILE_DISABLE=true; \
	tar --exclude '.svn' -zcvf soccer.tgz ../src)
else
	tar --exclude '.svn' -zcvf soccer.tgz ../src
endif
